package com.hw.one.dam2.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.hw.one.util.DateTimeUtil;

public class POIDemo {

	public static void main(String[] args) {
		// 以流的形式，读取模版
		InputStream inp = ExcelUtil.class.getResourceAsStream("/excelTemplates/dayReportTemplate.xlsx");
		// POIFSFileSystem fs=new POIFSFileSystem(inp);
		// 根据模版流，生成excel工作簿workbook
		try {
			Workbook wb = new XSSFWorkbook(inp);
			// 获取模版的Sheet
			Sheet sheet = wb.getSheetAt(0);
			// 获取模版的标题行
			Row titleRow = sheet.getRow(0);
			// 获取模版标题列
			Cell titleCell = titleRow.getCell(0);
			//设置标题值
			titleCell.setCellValue("xxx空气质量日报");
			
//			Row dataRow = sheet.getRow(2);
			titleRow = sheet.getRow(2);
			CellStyle defaultCellStyle = titleRow.getCell(0).getCellStyle();
			
			for(int i=2;i<6;i++){
				titleRow = sheet.createRow(i);
				titleRow.createCell(1).setCellValue("岗李水库");
				titleRow.createCell(1).setCellStyle(defaultCellStyle);
				
				//titleRow.getCell(1).setCellValue("岗李水库");
			}
						
			//输出  
	        OutputStream os = new FileOutputStream(new File("D://SummaryXSSF.xlsx"));  
	        wb.write(os);
	        wb.close();  
	        os.close(); 
	        System.out.println("导出Excel成功_"+DateTimeUtil.getFormatDateStr(Calendar.getInstance().getTime(),"yyyy-MM-dd HH:mm:ss"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
